<style lang="scss" scoped>
@import "../_init.scss";
@import "../_form.scss";
</style>

<template lang="pug">
.VUE
    form(@submit.prevent="submit" ref="form")
        .I-loading(v-if="mail===0")
        .P.TXT(v-else-if="mail===true")
            p 密码重置成功 
            p 
                a.button(href="/auth/login") 点此登录 
        .P.TXT(v-else-if="mail===''")
            p 验证链接已过期失效
            p 
                a.button(href="/auth/password/reset") 点此重新重置密码
        div(v-else)
            .P
                input(:value="mail" disabled)
                label.I.I-mail
            .P
                input(name="password" placeholder="请设置您的密码" type="password" v-model.trim="password" autofocus required)
                label.I.I-password
            p
                button(type="submit") 设置密码 
            p
                a.gray.button(href="/auth/login") 返回登录 
</template>

<script lang="coffee">
store = require 'store'

export default {
    data : ->
        {
            mail : 0
            password:""
        }
    mounted:->
        $(@$refs.form).find('input[type=password]').focus()

    methods:
        submit:->
            password = @password
            $(@$refs.form).save(
                "*auth/password/set"
                {
                    key:@$route.params.key
                    password
                }
                =>
                    store.set 'account', @mail
                    @mail = true
                (err)=>
                    require('../_err/password') err, password
            )


    mounted:->
        {key} = @$route.params
        @mail = await $.get("*auth/password/set-"+key)
}
</script>

